$(function () {
    const token = window.sessionStorage.getItem('token')
    $('form').on('submit', async e => {
        e.preventDefault()
        console.log($('.username').val());
        const username = $('.username').val()
        const rpassword = $('.rpassword').val()
        const password = $('.password').val()
        const nickname = $('.nickname').val()

        if (!username || !nickname || !password || !rpassword) return alert('请完整填写信息')

        if (password !== rpassword) return alert('两次密码填写需要一致')
        const res = $.ajax({
            url: 'http://localhost:8080/person/register',
            data: { username, nickname, password },
            method: 'post',
            headers: { authorization: token }
        })
        console.log(res);
        if (res.code === 1) {
            alert('注册成功')
            window.location.href = `./index.html`
            return
        }
        $('.error').text(res.message).show()
    })
})